package com.lz.gmall.item.rpc;

import com.lz.gmall.common.result.Result;
import com.lz.gmall.item.biz.SkuDetailBizService;
import com.lz.gmall.product.vo.SkuDetailVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("api/inner/item")
public class SkuDetailRpcController {

    @Autowired
    private SkuDetailBizService skuDetailBizService;


    /**
     * 远程调用接口开发，web-all调用改接口，该接口去调用service-product实现的四个接口
     * 拿到Sku的详细数据
     * 点击商品详情的时候，对商品的热点加一
     * @param skuId
     * @return
     */
    @GetMapping("detail/{skuId}")
    public Result<SkuDetailVo> getSkuDetailBySkuId(@PathVariable("skuId") Long skuId){
        SkuDetailVo skuDetailVo = skuDetailBizService.getSkuDetailBySkuId(skuId);
        //点击商品详情，就对redis中的热点加一，并判断是否修改热点
        skuDetailBizService.updateHotScore(skuId);
        return Result.ok(skuDetailVo);
    }


}
